<?php
import( 'de.ceus-media.service.YamlParametricServicePoint' );
import( 'de.ceus-media.adt.Reference' );
import( 'de.ceus-media.file.ini.IniReader' );
import( 'de.ceus-media.database.mysql.MySQL' );
import( 'de.ceus-media.protocol.http.PartitionSession' );
import( 'de.ceus-media.protocol.http.HTTP_RequestReceiver' );
import( 'de.ceus-media.framework.neon.Language' );
import( 'de.ceus-media.framework.neon.Messenger' );
class Services extends YamlParametricServicePoint
{
	public function __construct( $fileName )
	{
		parent::__construct( $fileName );
		
		error_reporting( 1023 );
		$ref	= new ADT_Reference;

		//  --  CONFIGURATION  --  //
		$ir		= new IniReader( "config/config.ini", true );
		$config	= $ir->toArray();
		$ir		= new IniReader( "config/rss.ini", true );
		$config['rss']	= $ir->toArray();
		$ref->add( "config",		$config );

		//  --  REQUEST HANDLING  --  //
		$request	= new HTTP_RequestReceiver();
		$ref->add( "request", $request );
		$ref->add( "messenger", new Messenger() );

		//  --  SESSION HANDLING  --  //
		$session	= new PartitionSession();
		$session->openSession( $config['application']['name'], $config['config']['session_name'] );
		$ref->add( "session", $session );

		//  --  DATABASE CONNECTION  --  //
		$ir			= new IniReader( "config/db_access.ini", false );
		$data		= $ir->toArray();
		$dbc		= new MySQL ( $data['logfile'] );
		$dbc->pconnect( $data['hostname'], $data['username'], $data['password'], $data['database'] );
		$config['config']['table_prefix']	= $data['prefix'];
		$ref->add( "dbc", $dbc );

		//  --  LANGUAGE SUPPORT  --  //
		$language	= new Language();
		$language->loadLanguage( 'main' );
		$ref->add( "language", $language );

		//  --  THEME SUPPORT  --  //
		$theme = $request->get( 'theme' );
		if( $theme !== NULL ) 
			$session->set( 'theme', $theme );
		if( $session->get( 'theme' ) )
			$config['layout']['theme'] =  $session->get( 'theme' );
		else
			$session->set( 'theme', $config['layout']['theme'] );
	}
}
?>